/***
 * @Description:
 * @Author: LI Yihong
 * @Email: liyh@jihua.ac.cn
 * @Date: 2025-02-26 14:32:30
 * @LastEditTime: 2025-02-26 14:32:30
 * @LastEditors: LI Yihong
 * @FilePath: \STM32F407_AD9910_Control\applications\TCP_SERVER\TEC_SERVER.hpp
 */
#pragma once
#include "cxx_thread.h"
#include <board.h>
#include <rtdevice.h>
#include <memory>
#include <vector>

using namespace std;
using namespace rtthread;

enum class TCP_FUNC : uint16_t
{

};

enum class TCP_FRAME_HEAD : uint8_t
{
    Single = 0x00,
    First = 0x01,
    Middle = 0x02,
    Last = 0x03
};

class TCP_SERVER : public Thread
{
private:
    enum class STATE_MACHINE
    {
        IDLE,
        WAIT_NEXT,
        ERROR_STATE,
        EXIT
    } m_state;

    TCP_SERVER(rt_uint32_t stack_size,
               rt_uint8_t priority,
               rt_uint32_t tick,
               const char *name);
    ~TCP_SERVER();
    TCP_SERVER(const TCP_SERVER &) = delete;
    TCP_SERVER &operator=(const TCP_SERVER &) = delete;

    std::vector<uint8_t> *m_recvData;
    bool dataReady;

public:
    static TCP_SERVER *getInstance();

    void run(void *parameter) override;
    void processData(const char *recvData, const int bytesReceived);
    std::vector<uint8_t> *getData();
};
